home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8443 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.4 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Schildt <- Advanced Books
  5. Date: 4 Mar 1996 01:36:10 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4he6hb$ahn@solutions.solon.com>
  8. References: <8BA8405.02C70020DE.uuout@sourcebbs.com> <4gnt96INN205@keats.ugrad.cs.ubc.ca> <4h4q0v$24v@redstone.interpath.net> <danpop.825687663@rscernix>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <danpop.825687663@rscernix>, Dan Pop <danpop@mail.cern.ch> wrote:
  12. >Sorry, I can hardly believe that.  Here are two examples (originally
  13. >posted by Lawrence Kirby) from page 53 of the _third_ edition of C-TCR:
  14.  
  15. >    float f
  16. >    printf("%f ", sizeof f);
  17. >    printf("%d", sizeof(int));
  18.  
  19. >and
  20.  
  21. >    void put_rec(int rec[6], FILE *fp)
  22. >    {
  23. >    int len;
  24. >
  25. >    len = fwrite(rec, sizeof rec, 1, fp);
  26. >    if(len != 1) printf("write error");
  27. >    }
  28.  
  29. Nit: I was the one who posted that one.  Lawrence posted one where it said
  30.     if(len<>1)...
  31. from the 2nd edition.
  32.  
  33. Yes.  Really.  It was <>.
  34.  
  35. >Both examples contain errors that could be made only by someone who
  36. >hasn't understood the language and are _very_ misleading for the
  37. >beginner, especially the second example (any beginner should be able
  38. >to spot (at least) one of the two mistakes in the first example).
  39.  
  40. I will point out that both of the errors in the first one are stupid,
  41. perhaps mindbogglingly so, but I have made both within the last six
  42. months or so.  If I had a nickel for every time I've typed a completely
  43. irrelevant format string, because I have no attention span, I'd have
  44. about a buck fifty.
  45.  
  46. >Both mistakes appeared in the second edition of the book, as well, and
  47. >they are NOT typos.  Ideally, the author shouldn't be allowed to
  48. >publish anything on a topic he is utterly unable to understand.
  49. >Unfortunately, the market realities of today are far from ideal :-(
  50.  
  51. I could consider the "%f" a typo; it is when I do it.  Believe me, I
  52. don't expect size_t to be a float-or-a-double.  The others are
  53. stunning; the size_t vs int bug is subtle.  The sizeof(ptr) bug
  54. is idiotic.
  55.  
  56. >Or how interpreters should not be written, if the code is written by
  57. >Schildt and not pasted from another source.
  58.  
  59. Well, although I didn't really look at the interpreter, I think it's
  60. instructive to look at the logic for a move choosing function.
  61.  
  62. I will make this clear: *I DID NOT MAKE THIS UP*.  I regret this;
  63. compared to some of my most obfuscated code, this is brilliant.
  64.  
  65.     void get_player_move(void)
  66.     {
  67.       int x, y;
  68.  
  69.       printf("Enter coordinates for your X: ");
  70.       scanf("%d%d", &x, &y);
  71.  
  72.       x--; y--;
  73.  
  74.       if(matrix[x][y]!= ' '){
  75.         printf("Invalid move, try again.\n");
  76.         get_player_move();
  77.       }
  78.       else matrix[x][y] = 'X';
  79.     }
  80.  
  81. The inconsistent or stupid spacing and brace style is *not* my fault;
  82. I checked it twice.
  83.  
  84. Can anyone find a single thing here with no mistakes?  Let's see...
  85. No fflush after the initial printf, no check for errors on scanf, no range
  86. checking, undefined behavior if scanf didn't fill both values, recursion
  87. on an input function.
  88.  
  89. The last line looks correct, but that's about *it*.
  90.  
  91. And yes, the whole book is really like this.
  92.  
  93. -s
  94. -- 
  95. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  96. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  97. FUCK the communications decency act.  Goddamned government.  [literally.]
  98. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  99.